<template>
  <div class="app-container">
    <div class="filter-container" style="overflow:hidden">
      {{$t('setting.Deposit')}}：
      <el-input-number style="margin-left:92px" v-model="price" :min="1"  label="描述文字"></el-input-number>
       {{$t('setting.AUD')}}
    </div>
    <div class="filter-container" style="overflow:hidden">
        {{$t('setting.Battery_setting')}}：
      <el-select v-model="power" @change="getPower2" style="margin-left:60px;">
        <el-option v-for="(item,index) in powers" :key="index" :label="item.desc" :value="item.id"></el-option>  
      </el-select>
      <div class="desc">({{$t('setting.allowed_power')}})</div>
    </div>
    <div class="filter-container" style="overflow:hidden">
       {{$t('setting.Free_trail_time')}}:
      <el-input-number style="margin-left:28px" v-model="timer" :min="1"  label="描述文字"></el-input-number>
      {{$t('setting.hour')}}
      <div class="desc">({{$t('setting.free_use')}})</div>
    </div>
    <div class="filter-container" style="overflow:hidden">
      {{$t('setting.Shop_icon_displaying_range')}}：
      <el-input-number style="margin-left:28px" v-model="range" :min="1"  label="描述文字"></el-input-number>
       {{$t('setting.within_km')}}
      <div class="desc">({{$t('setting.range_from_the_pin')}})</div>
    </div>
     <div class="filter-container" style="overflow:hidden">
      {{$t('setting.GST')}} ：
      <el-input style="margin-left:92px;width:200px;" v-model="gst"   label="描述文字"></el-input>
    </div>
     <div class="filter-container" style="overflow:hidden">
      Abn：
      <el-input style="margin-left:92px;width:200px;" v-model="abn"   label="描述文字"></el-input>
    </div>
    <!-- <div class="filter-container" style="overflow:hidden">
      美元对人名币比率：
      <el-input style="margin-left:10px;width:200px;" v-model="ratio"   label="描述文字"></el-input>
    </div> -->
    <el-button @click="confirm" type="primary" style="margin-top:50px;margin-left:10px;width:100px">{{$t('common.Save')}}</el-button>
  </div>
</template>

<script>
import { getSystemParamter , updateSystemParamter } from '@/api/system'
export default {
  name: 'setting_other',
  data(){
    return{
      price:'',
      power:'',
      timer:'',
      range:'',
      gst: '',
      abn: '',
      ratio: '',
      powers:[
        {id:0,desc:'20%'},
        {id:1,desc:'40%'},
        {id:2,desc:'60%'},
        {id:3,desc:'80%'},
        {id:4,desc:'100%'},
      ],
      power2:''
    }
  },
  methods:{
    getPower2(val){
      this.power2 = val
    },
    // 押金
    async getPrice(){
      const { data } = await getSystemParamter({
        key:'SYS00001',
      })
      this.price = data.systemValue
    },
    // 电量
    async getPower(){
      const { data } = await getSystemParamter({
        key:'SYS00002',
      })
      this.power = this.powers.filter(item=>item.id == data.systemValue)[0].desc
      this.power2 = data.systemValue
    },
    // 时长
    async getTimer(){
      const { data } = await getSystemParamter({
        key:'SYS00003',
      })
        this.timer = data.systemValue
    },
    // 范围
    async getRange(){
      const { data } = await getSystemParamter({
        key:'SYS00004',
      })
        this.range = data.systemValue
    },
    //GST
    async getGST(){
      const { data } = await getSystemParamter({
        key:'SYS00019',
      })
        this.gst = data.systemValue
    },
    //Abn
    async getAbn(){
      const { data } = await getSystemParamter({
        key:'SYS00020',
      })
        this.abn = data.systemValue
    },
    //比率
    async getRatio(){
      const { data } = await getSystemParamter({
        key:'SYS00021',
      })
        this.ratio = data.systemValue
    },
    async postPrice(){
      const{ data } = await updateSystemParamter({
          key:'SYS00001',
          value:this.price
        })  
    },
    async postPower(){
        const{ data } = await updateSystemParamter({
          key:'SYS00002',
          value:this.power2 
        })
    },
    async postTimer(){
      const{ data } = await updateSystemParamter({
          key:'SYS00003',
          value:this.timer
        })  
    },
    async postRange(){
        const{ data } = await updateSystemParamter({
          key:'SYS00004',
          value:this.range
        })
    },
    async postGST(){
        const{ data } = await updateSystemParamter({
          key:'SYS00019',
          value:this.gst
        })
    },
    async postAbn(){
        const{ data } = await updateSystemParamter({
          key:'SYS00020',
          value: this.abn
        })
    },
     async postRatio(){
        const{ data } = await updateSystemParamter({
          key:'SYS00021',
          value: this.ratio
        })
    },
    
    confirm(){
        if(!this.price  || !this.timer || !this.range || !this.gst || !this.abn)
        {
          this.$message({
              type:'error',
              message:'内容不能为空'
          });
          return
        }
         Promise.all([this.postPrice(), this.postPower(), this.postTimer(), this.postRange(),this.postGST(),this.postAbn()])
      .then(() => {
        this.$message({
          type: 'success',
          message: `修改成功!`
        });
        this.getPrice()
        this.getPower()
        this.getTimer()
        this.getRange()
        this.getGST()
        this.getAbn()
        
      })
      
    }
  },
  created(){
    this.getPrice()
    this.getPower()
    this.getTimer()
    this.getRange()
    this.getGST()
    this.getAbn()
  
  },
}
</script>

<style>
.desc{
  margin-top:10px;
  color:#cccccc;
  margin-left:150px;
  font-size:10px;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
}
</style>
